home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / ui / ProfilesManagerDlg.js < prev    next >
Encoding:
Text File  |  2007-04-11  |  6.5 KB  |  199 lines

  1. /****i* SOURCE_FILE/INFO
  2.     *
  3.     * NAME
  4.     *  ProfilesManagerDlg.js
  5.     *
  6.     * USAGE
  7.     *  Part of Netobjects JavaScript Library.
  8.     *
  9.     * COPYRIGHT
  10.     *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.     *  All Rights Reserved.
  12.     *
  13.     *  This is an unpublished work protected by Website Pros, Inc.
  14.     *  as a trade secret, and is not to be used or disclosed except as
  15.     *  expressly provided in a written license agreement executed by
  16.     *  you and Website Pros, Inc.
  17.     *
  18.     *      <copyright@websitepros.com>
  19.     *
  20.     * NOTES
  21.     *  JavaScript code.
  22.     *
  23.     *****/
  24.  
  25. if (!IS.isModuleInitialized("IS.NOF.UI.ProfilesManagerDlg"))
  26. {
  27.     
  28.     /****h* NOF_JavaScript_Library/NOF.UI.ProfilesManagerDlg
  29.     *
  30.     * NAME
  31.     *  NOF.UI.ProfilesManagerDlg
  32.     *
  33.     * DESCRIPTION
  34.     *
  35.     * External dependencies: NOF.UI.ListEditorDlg, NOF.UTIL.Validator, NOF.Contract, 
  36.     * NOF.DIALOGS.Messages, NOF.TEXT.MessageFormat, NOF.WindowEvent
  37.     ****/    
  38.     function NOF_ProfilesManager_Dialog( _editedElem, _document, _name ) {
  39.         this.__proto__ = NOF_ProfilesManager_Dialog.prototype;   
  40.         
  41.         if ( arguments.length == 0 )
  42.             this.SUPER();
  43.         else{
  44.             this.SUPER( _editedElem, _document, _name );
  45.             this.validator = new NOF.UTIL.Validator();
  46.             this.validator.setIsAlphaNum(true);    
  47.         }
  48.     }
  49.     
  50.     NOF_ProfilesManager_Dialog.inherits( NOF.UI.ListEditorDlg ); 
  51.     function NOF_ProfilesManager_Dialog_ProtoBuilder(){
  52.         
  53.         var member = NOF_ProfilesManager_Dialog.prototype;
  54.         member.defaultName = "GENERIC_PROFILE_DIALOG";
  55.         member.maxCharsDisplayedNo = 40;
  56.         
  57.         var method = NOF_ProfilesManager_Dialog.prototype;  
  58.         
  59.         method.onLoad = function onLoad() {
  60.             this.doc.initialize( this );
  61.             this.initFieldPropertyValues();
  62.             this.setTitle( this.getResourceProperty( "profiles.label.title" ) );
  63.             
  64.             this.getEditedElement().load();//make sure the object is loaded
  65.             var profiles = this.getEditedElement().getListElements();
  66.             
  67.             if (profiles.length > 0){
  68.                 var sMore = this.getResourceProperty( "label.longname.more" );
  69.                 var profilesList = new Array(profiles.length);    
  70.                 for (var i=0; i<profiles.length; i++) {
  71.                     var pName = profiles[i].name;
  72.                     NOF.Contract.Assert( pName !=null && pName.length > 0, "profile name cannot be null");
  73.                     if ( pName.length > this.maxCharsDisplayedNo ){
  74.                         pName = pName.substring( 0, this.maxCharsDisplayedNo - sMore.length ) + sMore;
  75.                     }
  76.                     
  77.                     profilesList[i] = [pName, profiles[i].id];
  78.                 }      
  79.                 
  80.                 this.doc.setElementItems('form.select.list', profilesList);
  81.             }
  82.             
  83.             this.onEnableRemoveButton( false );
  84.             this.onEnableOkButton( false );    
  85.             this.doc.focusElement( "profiles.text.name" );    
  86.         }
  87.         
  88.         method.onEnableRemoveButton = function onEnableRemoveButton( state ){
  89.             if (state)
  90.                 this.doc.enableElement( "profiles.button.remove" );
  91.             else
  92.                 this.doc.disableElement( "profiles.button.remove" );      
  93.         }
  94.         
  95.         method.onEnableOkButton = function onEnableOkButton( state ){
  96.             if (state)
  97.                 this.doc.enableElement( "profiles.button.ok" );
  98.             else
  99.                 this.doc.disableElement( "profiles.button.ok" );      
  100.         }
  101.         
  102.         method.getMaxCharsDisplayedNo  = function getMaxCharsDisplayedNo(){
  103.             return this.maxCharsDisplayedNo;
  104.         }
  105.         
  106.         method.setMaxCharsDisplayedNo = function setMaxCharsDisplayedNo(charsNo){
  107.             this.maxCharsDisplayedNo  =  charsNo;
  108.         }
  109.         
  110.         method.onOk = function onOk() {
  111.             var profList  = this.getEditedElement().getListElements();    
  112.             var pName    = this.doc.getElementValue( "profiles.text.name" );
  113.             for ( i = 0; i < profList.length; i++ ) {
  114.                 /*TODO: think this to accomodate also the case when a default exists and want to protect it
  115.                 if ( this.doc.getElementValue( "profiles.text.name" ) == "default" ) {
  116.                 alert( this.getResourceProperty( "profiles.label.defaultexists" ))
  117.                     this.doc.setElementValue( "profiles.text.name", "" );
  118.                 
  119.                 return false;
  120.                 }
  121.                 */
  122.                 
  123.                 if ( pName == profList[i].name ){
  124.                     var msg = NOF.TEXT.MessageFormat.format(this.getResourceProperty( "profiles.label.alreadyexists" ), pName);
  125.                     
  126.                     //if ( ! showwarning( msg ) ) {
  127.                     if ( ! NOF.DIALOGS.Messages.warning(msg, null, null, "", this.getResourceProperty( "label.yes"), this.getResourceProperty( "label.no"), this.doc.getRawDoc().parentWindow, 300, 90) ) {
  128.                         this.doc.focusElement( "profiles.text.name" );
  129.                         return false;
  130.                     }
  131.                 }
  132.             }
  133.             
  134.             //make sure we get the latest value from controls
  135.             this.getApp().dispatchEvent(new NOF.WindowEvent( "UpdateData", true));
  136.             
  137.             var newProfile = this.getEditedElement().getNewElement();
  138.             newProfile.verifyDoc();
  139.             this.setProfileData( newProfile );
  140.             newProfile.saveConfigFile( this.doc.getElementValue( "profiles.text.name" ) );
  141.             
  142.             this.getWindowHandle().close();
  143.         }
  144.         
  145.         method.setPofileData  = function setPofileData( profile ){
  146.             NOF.Contract.Assert("setPofileData is an abstract method!");    
  147.         }
  148.         
  149.         method.onRemove = function onRemove() {
  150.             //debugger;
  151.             var toRemove = this.doc.getElementValue('form.select.list');
  152.             
  153.             this.getEditedElement().remove( toRemove );
  154.             this.doc.removeElements('form.select.list', toRemove);
  155.             this.editedElement.setListElements ( this.doc.getElementItems('form.select.list') );
  156.             
  157.             var idx = this.doc.getElementItems('form.select.list').length;
  158.             if (idx == 0)
  159.                 this.onEnableRemoveButton( false );
  160.         }
  161.         
  162.         method.onKeyUp = function onKeyUp(source, window) {      
  163.             if (window.event.keyCode == 8 || window.event.keyCode == 46) 
  164.                 if (source.value.length == 0)
  165.                     this.onEnableOkButton( false );
  166.             
  167.             return true;
  168.         }
  169.         
  170.         method.onKeyDown = function onKeyDown(source, window) {
  171.             var chr = String.fromCharCode(window.event.keyCode);
  172.             var res = this.validator.validateInput(chr, source.value);
  173.             
  174.             if (source.value.length == 0 && res)
  175.                 this.onEnableOkButton( true );
  176.             
  177.             return res;
  178.         }
  179.         
  180.         method.onSelect = function onSelect() {
  181.             this.onEnableRemoveButton( true );
  182.         }
  183.         
  184.         
  185.         method.initFieldPropertyValues = function initFieldPropertyValues () {
  186.             var fieldPropertyValue = new Array();
  187.             
  188.             fieldPropertyValue['form.text.label']    = 'profiles.text.name';
  189.             fieldPropertyValue['form.select.list']   = 'profiles.select.list';
  190.             fieldPropertyValue['form.button.ok']     = 'profiles.button.ok';
  191.             fieldPropertyValue['form.button.remove'] = 'profiles.button.remove';
  192.             
  193.             this.doc.setPropertyMap(fieldPropertyValue);
  194.         }
  195.     } 
  196.     
  197.     NOF_ProfilesManager_Dialog_ProtoBuilder();  
  198.     UI.__proto__.ProfilesManagerDlg = NOF_ProfilesManager_Dialog;    
  199. }